<!-- templates\admin.html -->
{% extends "base.html" %}
{% block content %}
<h1>Admin Dashboard</h1>

<!-- User Management -->
<h2>Users</h2>
<table>
  <thead>
    <tr>
      <th>Username</th>
      <th>Email</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    {% for user in users %}
    <tr>
      <td>{{ user.username }}</td>
      <td>{{ user.email }}</td>
      <td>
        <a class="button" href="{{ url_for('delete_user', user_id=user.id) }}">Delete</a>
        <a class="button" href="{{ url_for('make_admin', user_id=user.id) }}">Make Admin</a>
        <a class="button" href="{{ url_for('remove_admin', user_id=user.id) }}">Remove Admin</a>
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
<hr>
<!-- Post Management -->
<h2>Posts</h2>
<table>
  <thead>
    <tr>
      <th>Title</th>
      <th>Author</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    {% for post in posts %}
    <tr>
      <td><a href="{{ url_for('view_post', post_id=post.id) }}">{{ post.title }}</a></td>
      <td>{{ post.author.username }}</td>
      <td>
        <a class="button" href="{{ url_for('delete_post', post_id=post.id) }}">Delete</a>
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
<hr>
<h2>Files </h2>
<table>
  <thead>
    <tr>
      <th>File Name</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    {% for file in files %}
    <tr>
      <td><a href="{{ url_for('download_file', file_id=file.id) }}">{{ file.filename }}</a></td>
      <td>
        <a class="button" href="{{ url_for('delete_file', file_id=file.id)}}">Delete</a>
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
<script>
  window.onload = function load(){
    document.getElementById("admin").className="active";
  }
</script>
{% endblock %}